
#ifndef INTLWIDGET_H
#define INTLWIDGET_H
#include <QPushButton>
#include <QVBoxLayout>
#include <QWidget>
#include <QButtonGroup>
#include <memory>
#include <QJsonObject>
#include <QLabel>
#include <QVector>
#include <QHash>
#include "utils.h"
#include <QLineEdit>
#include <QTextEdit>
#include <QNetworkAccessManager>
class IntlWidget : public QWidget
{
  using CacheMap = QHash<QString,LanguageConfig>;
  using IntlFiles = std::tuple<QString,QString>;
  Q_OBJECT

public:
  IntlWidget(QWidget *parent);
  ~IntlWidget();

private:
  QNetworkAccessManager *network;
  QPushButton *buttonSelectConfig;
  QPushButton *buttonSelecctIntlDir;
  QPushButton *buttonInsert;
  QVBoxLayout *container;
  QLabel *labelIntlSelected;
  QLabel *labelConfig;

  QPushButton *buttonWriteConfig;

  // QJsonObject zhJson;
  // QJsonObject enJson;

  ///LanguageConfig
  QVector<LanguageConfig> configs;
  ///key:LanguageConfig
  CacheMap caches;
  IntlFiles intlFiles;

  QLineEdit *lineEditInsertZH;
  QLineEdit *lineEditInsertEN;
  QTextEdit *textEditInsertResult;

  // QString generateKey(const QVector<LanguageConfig>)

  QString generatePinyinKey(const CacheMap &caches,const QString &pinyinReplaceHolder);
  LanguageConfig replaceLaunagePlaceholder(const LanguageConfig &config);
  QString replaceValuePlaceholder(const QString &origin);
  QString replaceKeyPlaceholder(const QString &origin);
  bool rewrite();
  void updateIntlCount();
  LanguageConfig insertToCaches(const LanguageConfig &config);

private slots:
  void onSelectConfigClicked();
  void onSelectIntlDirClicked();
  void onConfigWriteClicked();
  void onInsertClicked();
};
#endif